package main

import (
	"time"

	"github.com/andlabs/ui"
)

type MyAreaHandler struct {
}

func (*MyAreaHandler) Draw(a *ui.Area, dp *ui.AreaDrawParams) {

}

func (*MyAreaHandler) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) {

}

func (*MyAreaHandler) MouseCrossed(a *ui.Area, left bool) {

}

func (*MyAreaHandler) DragBroken(a *ui.Area) {

}

func (*MyAreaHandler) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) {
	return false
}

func main() {

	err := ui.Main(func() {
		combobox := ui.NewCombobox() //下拉框
		name := ui.NewEntry()
		group := ui.NewGroup("this is group") //组合框
		group.SetMargined(true)
		group.SetChild(name)
		button := ui.NewButton("button")
		show := ui.NewLabel("greeting")
		count := ui.NewLabel("count")
		bar := ui.NewProgressBar()
		slider := ui.NewSlider(0, 100)   //水平播放条
		spinBox := ui.NewSpinbox(10, 20) //鼠标调整输入框
		tab := ui.NewTab()               //横向分割条


		verticalBox := ui.NewVerticalBox()
		verticalBox.Append(ui.NewLabel("Enter your name:"), false)
		verticalBox.Append(group, false)
		verticalBox.Append(button, false)
		verticalBox.Append(show, false)
		verticalBox.Append(count, false)
		verticalBox.Append(bar, false)
		verticalBox.Append(slider, false)
		verticalBox.Append(spinBox, false)
		verticalBox.Append(tab, true)

		window := ui.NewWindow("this is window", 200, 100, false)
		horizontalBox := ui.NewHorizontalBox()
		window.SetChild(horizontalBox)
		horizontalBox.Append(verticalBox, false)
		separator := ui.NewHorizontalSeparator()
		horizontalBox.Append(separator, true)
		horizontalBox.Append(combobox, false)


		button.OnClicked(func(*ui.Button) {
			show.SetText("Hello, " + name.Text() + "!")
		})
		window.OnClosing(func(*ui.Window) bool {
			ui.Quit()
			return true
		})
		window.Show()

		go doCount(count)
	})
	if err != nil {
		panic(err)
	}
}

func doCount(label *ui.Label) {
	for {
		time.Sleep(time.Second)
		ui.QueueMain(func() {
			label.SetText(time.Now().Format("2006-01-02 15:04:05"))
		})
	}
}
